/**
 * 
 */
package com.scpii.universal.hibernate.dao.impl;

import java.util.List;

import org.hibernate.Hibernate;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.dto.PageNavigationIconDto;
import com.scpii.universal.hibernate.dao.PageNavigationIconDao;

/**
 * 
 * @author chenxin 2012-7-6上午10:16:50
 */
@Repository
public class PageNavigaionIconDaoImpl extends
		BaseDaoImpl<PageNavigationIconDto, Integer> implements
		PageNavigationIconDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<PageNavigationIconDto> getNavigationIconByAppId(int appId) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT p.INT_NAVIGATE_ID,p.VAR_NAVIGATE_NAME,p.INT_NAVIGATE_ORDER,");
		sql.append("p.INT_DELETE_SIGN,p.INT_NAVIGATE_TYPE,p.INT_APP_ID,");
		sql.append("p.INT_NAVIGATE_ICON_ID,a.VAR_ICON_URL,p.INT_RESOURCE_ID");
		sql.append(" FROM PAGE_NAVIGATION_TAB p LEFT JOIN APP_ICON_TAB a ON p.INT_NAVIGATE_ICON_ID=a.INT_ICON_ID");
		sql.append(" where p.INT_DELETE_SIGN=? and p.INT_APP_ID=?");
		sql.append(" ORDER BY p.INT_NAVIGATE_ORDER ASC");

		return getHibernateTemplate().getSessionFactory().getCurrentSession()
				.createSQLQuery(sql.toString()).addScalar("INT_NAVIGATE_ID",
						Hibernate.INTEGER).addScalar("VAR_NAVIGATE_NAME",
						Hibernate.STRING).addScalar("INT_NAVIGATE_ORDER",
						Hibernate.BYTE).addScalar("INT_DELETE_SIGN",
						Hibernate.INTEGER).addScalar("INT_NAVIGATE_TYPE",
						Hibernate.INTEGER).addScalar("INT_APP_ID",
						Hibernate.INTEGER).addScalar("INT_NAVIGATE_ICON_ID",
						Hibernate.INTEGER).addScalar("VAR_ICON_URL",
						Hibernate.STRING).addScalar("INT_RESOURCE_ID",
						Hibernate.INTEGER).setResultTransformer(
						Transformers.aliasToBean(PageNavigationIconDto.class))
				.setParameter(0, GenericConstants.DELETE_SIGN_EXIST)
				.setParameter(1, appId).list();
	}

}
